import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem =new int[10] ;
    }

    @Override
    public String toString() {
        return "MyStack{" +
                "elem=" + Arrays.toString(elem) +
                ", usedSize=" + usedSize +
                '}';
    }

    public void push(int val) {
        if (isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull() {
        if (usedSize == elem.length) {
            return true;
        }
        return false;
    }
    public int pop() {
        if(isEmpty()) {
            throw new EmptyException("栈为空！");
        }
        int val = elem[usedSize-1];
        usedSize--;
        return val;
    }
    public boolean isEmpty() {
        return usedSize == 0;
    }
    public int peek() {
        if (isEmpty()) {
            throw new EmptyException("栈为空！");
        }
        return elem[usedSize-1];
    }
}
